<?php

class Default_Form_Comment extends Zend_Form {

    private $id; // l'id de l'utilisateur

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function init() {
// le nom du formulaire
        $this->setName('formComment');
        $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

//element hidden id pour l'utilisation du formulaire lors de la modification d'un utilisateur
        $id = new Zend_Form_Element_Hidden('id');

//element texte firstname
        $comment_firstname = new Zend_Form_Element_Text('comment_firstname');
        $comment_firstname->setLabel('form_event_comment_firstname')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');
        $comment_name = new Zend_Form_Element_Text('comment_name');
        $comment_name->setLabel('form_event_comment_name')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

//element texte content
        $content = new Zend_Form_Element_Textarea('comment_content');
        $content->setLabel('form_event_content')
                ->setRequired(true)
                ->setAttrib('COLS', '40')
                ->setAttrib('ROWS', '4');
//bouton submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
                ->setLabel('form_user_submit');

// on ajoute tous les éléments du formulaire dans un tableau
        $elements = array($id, $comment_firstname, $comment_name, $content, $submit);

// on ajoute ce tableau d'éléments au formulaire
        $this->addElements($elements);

        $id = $this->getId();
        if (isset($id) && $id != "") {
            $mod = new Application_Model_EventModel ( );
            $eventFound = $mod->read($id)->toArray();
            if ($eventFound != null) {
                $this->populate($eventFound);
            } else {
                throw new Zend_Exception("form_user_no_id");
            }
        }
    }

}

